package com.todo.sight.application.api.controller;

import com.todo.common.common.entity.response.BizResponse;
import com.todo.sight.application.convert.SightServiceConvert;
import com.todo.sight.application.entity.bo.SightBaseBO;
import com.todo.sight.application.entity.bo.SightDetailBO;
import com.todo.sight.application.service.SightService;
import com.todo.sight.service.api.SightInfoApi;
import com.todo.sight.service.api.response.SightDetailResponse;
import com.todo.sight.service.api.response.SightInfoResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author azhebuxing
 * @date 2025/2/26 19:29
 * @description
 */
@RestController
@RequestMapping("/api/sightInfo")
@Tag(name = "服务端-景点详情接口", description = "服务端-景点详情接口")
public class SightInfoApiController implements SightInfoApi {

    @Resource
    private SightService sightService;

    @Override
    @Operation(summary = "根据景点Id查询景点详情")
    @PostMapping("/querySightDetailById")
    public BizResponse<SightDetailResponse> querySightDetailById(@RequestBody Long sightId) {
        if (sightId == null || sightId < 0) {
            return BizResponse.paramError();
        }
        SightDetailBO sightDetailBO = sightService.querySightDetailById(sightId);
        return BizResponse.success(SightServiceConvert.convertToSightDetailResponse(sightDetailBO));
    }

    @Override
    @Operation(summary = "根据PoiId查询景点详情")
    @PostMapping("/querySightDetailByPoiId")
    public BizResponse<SightDetailResponse> querySightDetailByPoiId(@RequestBody Long poiId) {
        if (poiId == null || poiId < 0) {
            return BizResponse.paramError();
        }
        SightDetailBO sightDetailBO = sightService.querySightDetailByPoi(poiId);
        return BizResponse.success(SightServiceConvert.convertToSightDetailResponse(sightDetailBO));
    }

    @Override
    @Operation(summary = "根据poiIdList查询景点详情")
    @PostMapping("/querySightInfoByPoiIdList")
    public BizResponse<List<SightInfoResponse>> querySightInfoByPoiIdList(@RequestBody List<Long> poiIdList) {
        if (CollectionUtils.isEmpty(poiIdList)) {
            return BizResponse.paramError();
        }
        List<SightBaseBO> sightBaseBOS = sightService.querySightInfoByPoiIdList(poiIdList);
        return BizResponse.success(sightBaseBOS.stream().map(SightServiceConvert::convertToSightInfoResponse).collect(Collectors.toList()));
    }

    @Override
    @Operation(summary = "根据sightIdList查询景点详情")
    @PostMapping("/querySightInfoByIdList")
    public BizResponse<List<SightInfoResponse>> querySightInfoByIdList(@RequestBody List<Long> sightIdList) {
        if (CollectionUtils.isEmpty(sightIdList)) {
            return BizResponse.paramError();
        }
        List<SightBaseBO> sightBaseBOS = sightService.querySightBaseById(sightIdList);
        return BizResponse.success(sightBaseBOS.stream().map(SightServiceConvert::convertToSightInfoResponse).collect(Collectors.toList()));
    }
}
